"""
CGL/ANGLE: GL backend implementation using ANGLE.
"""

include "../common.pxi"
include "../../include/config.pxi"

from kivy.graphics.cgl cimport *

cdef extern from *:
    """
    #if __USE_ANGLE_GL_BACKEND
        #include "EGL/egl.h"
    #endif
    """
    void *eglGetProcAddress(const char * procname)

cpdef is_backend_supported():
    return USE_ANGLE_GL_BACKEND

def init_backend():
    if not USE_ANGLE_GL_BACKEND:
        raise Exception('ANGLE GL backend is not supported')

    cgl.glActiveTexture = <GLACTIVETEXTUREPTR>eglGetProcAddress("glActiveTexture")
    cgl.glAttachShader = <GLATTACHSHADERPTR>eglGetProcAddress("glAttachShader")
    cgl.glBindAttribLocation = <GLBINDATTRIBLOCATIONPTR>eglGetProcAddress("glBindAttribLocation")
    cgl.glBindBuffer = <GLBINDBUFFERPTR>eglGetProcAddress("glBindBuffer")
    cgl.glBindFramebuffer = <GLBINDFRAMEBUFFERPTR>eglGetProcAddress("glBindFramebuffer")
    cgl.glBindRenderbuffer = <GLBINDRENDERBUFFERPTR>eglGetProcAddress("glBindRenderbuffer")
    cgl.glBindTexture = <GLBINDTEXTUREPTR>eglGetProcAddress("glBindTexture")
    cgl.glBlendColor = <GLBLENDCOLORPTR>eglGetProcAddress("glBlendColor")
    cgl.glBlendEquation = <GLBLENDEQUATIONPTR>eglGetProcAddress("glBlendEquation")
    cgl.glBlendEquationSeparate = <GLBLENDEQUATIONSEPARATEPTR>eglGetProcAddress("glBlendEquationSeparate")
    cgl.glBlendFunc = <GLBLENDFUNCPTR>eglGetProcAddress("glBlendFunc")
    cgl.glBlendFuncSeparate = <GLBLENDFUNCSEPARATEPTR>eglGetProcAddress("glBlendFuncSeparate")
    cgl.glBufferData = <GLBUFFERDATAPTR>eglGetProcAddress("glBufferData")
    cgl.glBufferSubData = <GLBUFFERSUBDATAPTR>eglGetProcAddress("glBufferSubData")
    cgl.glCheckFramebufferStatus = <GLCHECKFRAMEBUFFERSTATUSPTR>eglGetProcAddress("glCheckFramebufferStatus")
    cgl.glClear = <GLCLEARPTR>eglGetProcAddress("glClear")
    cgl.glClearColor = <GLCLEARCOLORPTR>eglGetProcAddress("glClearColor")
    cgl.glClearStencil = <GLCLEARSTENCILPTR>eglGetProcAddress("glClearStencil")
    cgl.glColorMask = <GLCOLORMASKPTR>eglGetProcAddress("glColorMask")
    cgl.glCompileShader = <GLCOMPILESHADERPTR>eglGetProcAddress("glCompileShader")
    cgl.glCompressedTexImage2D = <GLCOMPRESSEDTEXIMAGE2DPTR>eglGetProcAddress("glCompressedTexImage2D")
    cgl.glCompressedTexSubImage2D = <GLCOMPRESSEDTEXSUBIMAGE2DPTR>eglGetProcAddress("glCompressedTexSubImage2D")
    cgl.glCopyTexImage2D = <GLCOPYTEXIMAGE2DPTR>eglGetProcAddress("glCopyTexImage2D")
    cgl.glCopyTexSubImage2D = <GLCOPYTEXSUBIMAGE2DPTR>eglGetProcAddress("glCopyTexSubImage2D")
    cgl.glCreateProgram = <GLCREATEPROGRAMPTR>eglGetProcAddress("glCreateProgram")
    cgl.glCreateShader = <GLCREATESHADERPTR>eglGetProcAddress("glCreateShader")
    cgl.glCullFace = <GLCULLFACEPTR>eglGetProcAddress("glCullFace")
    cgl.glDeleteBuffers = <GLDELETEBUFFERSPTR>eglGetProcAddress("glDeleteBuffers")
    cgl.glDeleteFramebuffers = <GLDELETEFRAMEBUFFERSPTR>eglGetProcAddress("glDeleteFramebuffers")
    cgl.glDeleteProgram = <GLDELETEPROGRAMPTR>eglGetProcAddress("glDeleteProgram")
    cgl.glDeleteRenderbuffers = <GLDELETERENDERBUFFERSPTR>eglGetProcAddress("glDeleteRenderbuffers")
    cgl.glDeleteShader = <GLDELETESHADERPTR>eglGetProcAddress("glDeleteShader")
    cgl.glDeleteTextures = <GLDELETETEXTURESPTR>eglGetProcAddress("glDeleteTextures")
    cgl.glDepthFunc = <GLDEPTHFUNCPTR>eglGetProcAddress("glDepthFunc")
    cgl.glDepthMask = <GLDEPTHMASKPTR>eglGetProcAddress("glDepthMask")
    cgl.glDetachShader = <GLDETACHSHADERPTR>eglGetProcAddress("glDetachShader")
    cgl.glDisable = <GLDISABLEPTR>eglGetProcAddress("glDisable")
    cgl.glDisableVertexAttribArray = <GLDISABLEVERTEXATTRIBARRAYPTR>eglGetProcAddress("glDisableVertexAttribArray")
    cgl.glDrawArrays = <GLDRAWARRAYSPTR>eglGetProcAddress("glDrawArrays")
    cgl.glDrawElements = <GLDRAWELEMENTSPTR>eglGetProcAddress("glDrawElements")
    cgl.glEnable = <GLENABLEPTR>eglGetProcAddress("glEnable")
    cgl.glEnableVertexAttribArray = <GLENABLEVERTEXATTRIBARRAYPTR>eglGetProcAddress("glEnableVertexAttribArray")
    cgl.glFinish = <GLFINISHPTR>eglGetProcAddress("glFinish")
    cgl.glFlush = <GLFLUSHPTR>eglGetProcAddress("glFlush")
    cgl.glFramebufferRenderbuffer = <GLFRAMEBUFFERRENDERBUFFERPTR>eglGetProcAddress("glFramebufferRenderbuffer")
    cgl.glFramebufferTexture2D = <GLFRAMEBUFFERTEXTURE2DPTR>eglGetProcAddress("glFramebufferTexture2D")
    cgl.glFrontFace = <GLFRONTFACEPTR>eglGetProcAddress("glFrontFace")
    cgl.glGenBuffers = <GLGENBUFFERSPTR>eglGetProcAddress("glGenBuffers")
    cgl.glGenerateMipmap = <GLGENERATEMIPMAPPTR>eglGetProcAddress("glGenerateMipmap")
    cgl.glGenFramebuffers = <GLGENFRAMEBUFFERSPTR>eglGetProcAddress("glGenFramebuffers")
    cgl.glGenRenderbuffers = <GLGENRENDERBUFFERSPTR>eglGetProcAddress("glGenRenderbuffers")
    cgl.glGenTextures = <GLGENTEXTURESPTR>eglGetProcAddress("glGenTextures")
    cgl.glGetActiveAttrib = <GLGETACTIVEATTRIBPTR>eglGetProcAddress("glGetActiveAttrib")
    cgl.glGetActiveUniform = <GLGETACTIVEUNIFORMPTR>eglGetProcAddress("glGetActiveUniform")
    cgl.glGetAttachedShaders = <GLGETATTACHEDSHADERSPTR>eglGetProcAddress("glGetAttachedShaders")
    cgl.glGetAttribLocation = <GLGETATTRIBLOCATIONPTR>eglGetProcAddress("glGetAttribLocation")
    cgl.glGetBooleanv = <GLGETBOOLEANVPTR>eglGetProcAddress("glGetBooleanv")
    cgl.glGetBufferParameteriv = <GLGETBUFFERPARAMETERIVPTR>eglGetProcAddress("glGetBufferParameteriv")
    cgl.glGetError = <GLGETERRORPTR>eglGetProcAddress("glGetError")
    cgl.glGetFloatv = <GLGETFLOATVPTR>eglGetProcAddress("glGetFloatv")
    cgl.glGetFramebufferAttachmentParameteriv = <GLGETFRAMEBUFFERATTACHMENTPARAMETERIVPTR>eglGetProcAddress("glGetFramebufferAttachmentParameteriv")
    cgl.glGetIntegerv = <GLGETINTEGERVPTR>eglGetProcAddress("glGetIntegerv")
    cgl.glGetProgramInfoLog = <GLGETPROGRAMINFOLOGPTR>eglGetProcAddress("glGetProgramInfoLog")
    cgl.glGetProgramiv = <GLGETPROGRAMIVPTR>eglGetProcAddress("glGetProgramiv")
    cgl.glGetRenderbufferParameteriv = <GLGETRENDERBUFFERPARAMETERIVPTR>eglGetProcAddress("glGetRenderbufferParameteriv")
    cgl.glGetShaderInfoLog = <GLGETSHADERINFOLOGPTR>eglGetProcAddress("glGetShaderInfoLog")
    cgl.glGetShaderiv = <GLGETSHADERIVPTR>eglGetProcAddress("glGetShaderiv")
    cgl.glGetShaderSource = <GLGETSHADERSOURCEPTR>eglGetProcAddress("glGetShaderSource")
    cgl.glGetString = <GLGETSTRINGPTR>eglGetProcAddress("glGetString")
    cgl.glGetTexParameterfv = <GLGETTEXPARAMETERFVPTR>eglGetProcAddress("glGetTexParameterfv")
    cgl.glGetTexParameteriv = <GLGETTEXPARAMETERIVPTR>eglGetProcAddress("glGetTexParameteriv")
    cgl.glGetUniformfv = <GLGETUNIFORMFVPTR>eglGetProcAddress("glGetUniformfv")
    cgl.glGetUniformiv = <GLGETUNIFORMIVPTR>eglGetProcAddress("glGetUniformiv")
    cgl.glGetUniformLocation = <GLGETUNIFORMLOCATIONPTR>eglGetProcAddress("glGetUniformLocation")
    cgl.glGetVertexAttribfv = <GLGETVERTEXATTRIBFVPTR>eglGetProcAddress("glGetVertexAttribfv")
    cgl.glGetVertexAttribiv = <GLGETVERTEXATTRIBIVPTR>eglGetProcAddress("glGetVertexAttribiv")
    cgl.glHint = <GLHINTPTR>eglGetProcAddress("glHint")
    cgl.glIsBuffer = <GLISBUFFERPTR>eglGetProcAddress("glIsBuffer")
    cgl.glIsEnabled = <GLISENABLEDPTR>eglGetProcAddress("glIsEnabled")
    cgl.glIsFramebuffer = <GLISFRAMEBUFFERPTR>eglGetProcAddress("glIsFramebuffer")
    cgl.glIsProgram = <GLISPROGRAMPTR>eglGetProcAddress("glIsProgram")
    cgl.glIsRenderbuffer = <GLISRENDERBUFFERPTR>eglGetProcAddress("glIsRenderbuffer")
    cgl.glIsShader = <GLISSHADERPTR>eglGetProcAddress("glIsShader")
    cgl.glIsTexture = <GLISTEXTUREPTR>eglGetProcAddress("glIsTexture")
    cgl.glLineWidth = <GLLINEWIDTHPTR>eglGetProcAddress("glLineWidth")
    cgl.glLinkProgram = <GLLINKPROGRAMPTR>eglGetProcAddress("glLinkProgram")
    cgl.glPixelStorei = <GLPIXELSTOREIPTR>eglGetProcAddress("glPixelStorei")
    cgl.glPolygonOffset = <GLPOLYGONOFFSETPTR>eglGetProcAddress("glPolygonOffset")
    cgl.glReadPixels = <GLREADPIXELSPTR>eglGetProcAddress("glReadPixels")
    cgl.glRenderbufferStorage = <GLRENDERBUFFERSTORAGEPTR>eglGetProcAddress("glRenderbufferStorage")
    cgl.glSampleCoverage = <GLSAMPLECOVERAGEPTR>eglGetProcAddress("glSampleCoverage")
    cgl.glScissor = <GLSCISSORPTR>eglGetProcAddress("glScissor")
    cgl.glShaderBinary = <GLSHADERBINARYPTR>eglGetProcAddress("glShaderBinary")
    cgl.glShaderSource = <GLSHADERSOURCEPTR>eglGetProcAddress("glShaderSource")
    cgl.glStencilFunc = <GLSTENCILFUNCPTR>eglGetProcAddress("glStencilFunc")
    cgl.glStencilFuncSeparate = <GLSTENCILFUNCSEPARATEPTR>eglGetProcAddress("glStencilFuncSeparate")
    cgl.glStencilMask = <GLSTENCILMASKPTR>eglGetProcAddress("glStencilMask")
    cgl.glStencilMaskSeparate = <GLSTENCILMASKSEPARATEPTR>eglGetProcAddress("glStencilMaskSeparate")
    cgl.glStencilOp = <GLSTENCILOPPTR>eglGetProcAddress("glStencilOp")
    cgl.glStencilOpSeparate = <GLSTENCILOPSEPARATEPTR>eglGetProcAddress("glStencilOpSeparate")
    cgl.glTexImage2D = <GLTEXIMAGE2DPTR>eglGetProcAddress("glTexImage2D")
    cgl.glTexParameterf = <GLTEXPARAMETERFPTR>eglGetProcAddress("glTexParameterf")
    cgl.glTexParameteri = <GLTEXPARAMETERIPTR>eglGetProcAddress("glTexParameteri")
    cgl.glTexSubImage2D = <GLTEXSUBIMAGE2DPTR>eglGetProcAddress("glTexSubImage2D")
    cgl.glUniform1f = <GLUNIFORM1FPTR>eglGetProcAddress("glUniform1f")
    cgl.glUniform1fv = <GLUNIFORM1FVPTR>eglGetProcAddress("glUniform1fv")
    cgl.glUniform1i = <GLUNIFORM1IPTR>eglGetProcAddress("glUniform1i")
    cgl.glUniform1iv = <GLUNIFORM1IVPTR>eglGetProcAddress("glUniform1iv")
    cgl.glUniform2f = <GLUNIFORM2FPTR>eglGetProcAddress("glUniform2f")
    cgl.glUniform2fv = <GLUNIFORM2FVPTR>eglGetProcAddress("glUniform2fv")
    cgl.glUniform2i = <GLUNIFORM2IPTR>eglGetProcAddress("glUniform2i")
    cgl.glUniform2iv = <GLUNIFORM2IVPTR>eglGetProcAddress("glUniform2iv")
    cgl.glUniform3f = <GLUNIFORM3FPTR>eglGetProcAddress("glUniform3f")
    cgl.glUniform3fv = <GLUNIFORM3FVPTR>eglGetProcAddress("glUniform3fv")
    cgl.glUniform3i = <GLUNIFORM3IPTR>eglGetProcAddress("glUniform3i")
    cgl.glUniform3iv = <GLUNIFORM3IVPTR>eglGetProcAddress("glUniform3iv")
    cgl.glUniform4f = <GLUNIFORM4FPTR>eglGetProcAddress("glUniform4f")
    cgl.glUniform4fv = <GLUNIFORM4FVPTR>eglGetProcAddress("glUniform4fv")
    cgl.glUniform4i = <GLUNIFORM4IPTR>eglGetProcAddress("glUniform4i")
    cgl.glUniform4iv = <GLUNIFORM4IVPTR>eglGetProcAddress("glUniform4iv")
    cgl.glUniformMatrix4fv = <GLUNIFORMMATRIX4FVPTR>eglGetProcAddress("glUniformMatrix4fv")
    cgl.glUseProgram = <GLUSEPROGRAMPTR>eglGetProcAddress("glUseProgram")
    cgl.glValidateProgram = <GLVALIDATEPROGRAMPTR>eglGetProcAddress("glValidateProgram")
    cgl.glVertexAttrib1f = <GLVERTEXATTRIB1FPTR>eglGetProcAddress("glVertexAttrib1f")
    cgl.glVertexAttrib2f = <GLVERTEXATTRIB2FPTR>eglGetProcAddress("glVertexAttrib2f")
    cgl.glVertexAttrib3f = <GLVERTEXATTRIB3FPTR>eglGetProcAddress("glVertexAttrib3f")
    cgl.glVertexAttrib4f = <GLVERTEXATTRIB4FPTR>eglGetProcAddress("glVertexAttrib4f")
    cgl.glVertexAttribPointer = <GLVERTEXATTRIBPOINTERPTR>eglGetProcAddress("glVertexAttribPointer")
    cgl.glViewport = <GLVIEWPORTPTR>eglGetProcAddress("glViewport")